#include "EditorRegionManager.hpp"

EditorRegionManager::EditorRegionManager(){
    
}

void EditorRegionManager::update(unsigned int frameTime){
    for(int i = 0; i < size; i++){
        if(regions[i]){
            //Run update script, to implement later.
        }
    }
}

Region* EditorRegionManager::createRegion(const char* name){
    for(unsigned short i = 0; i < size; i++){
        if(regions[i] == 0){
            regions[i] = new EditorRegion();
            regions[i]->setName("unititled");
            regions[i]->init(name, i);
            return regions[i];
        }
    }
    return 0;
}

bool EditorRegionManager::destroyRegion(Region* region){
    for(unsigned short i = 0; i < size; i++){
        if(regions[i] == region){
            delete regions[i];
            regions[i] = 0;
            return true;
        }
    }
    return false;
}

/**
 * Destroy region at given index
 * @param index Index of region to destroy.
 * @returns true if destroyed, false otherwise.
 */
bool EditorRegionManager::destroyRegion(unsigned short index){
    if(regions[index]){
        delete regions[index];
        regions[index] = 0;
        return true;
    }
    return false;
}

void EditorRegionManager::bind(lua_State* luaState){
    //To be implemented.
}
void EditorRegionManager::push(lua_State* luaState){
    //To be implemented.
}